package com.li.senbiao.serial.defaultt;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

public class Main {
	public static void main(String[] args) {
		Main main = new Main();
		TestSerial ts = new TestSerial();
		main.objectToFile(ts);
		
		TestSerial newTestSerial = main.FileToObject();
		System.out.println("version=" + newTestSerial.version);

	}

	public void objectToFile(TestSerial ts) {
		FileOutputStream fos = null;
		try {
			fos = new FileOutputStream("TestSerial");
			ObjectOutputStream oos = new ObjectOutputStream(fos);
			oos.writeObject(ts);
			oos.flush();
			oos.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public TestSerial FileToObject() {
		FileInputStream fis;
		TestSerial ts = null;
		try {
			fis = new FileInputStream("TestSerial");
			ObjectInputStream oin = new ObjectInputStream(fis);
			 ts = (TestSerial) oin.readObject();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return ts;
	}

}
